<template>
  <div class="Search">
    <div class="search-wrap">
      <input
        class="search-ipt"
        type="search"
        v-model.trim="jobName"
        placeholder="搜索职位、公司"
        @input="SerachChange"
      />
      <button class="search-btn" @click="getSearch">搜索</button>
    </div>
    <div class="search-hidden" v-if="isSearchList">
      <div
        class="search-hidden-list"
        v-for="(item, index) in searchData"
        :key="index"
      >
        {{ item.jobName }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Search',
  components: {},
  data() {
    return {
      jobName: '',
      searchData: [],
      isSearchList: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getSearchList()
  },
  mounted() {},
  methods: {
    getSearchList() {
      this.searchData = []
    },
    // 点击获取搜索框焦点
    // SearchIpt() {
    //   this.isSearchList = !this.isSearchList
    // },
    // 搜索框的值改变时
    SerachChange() {
      // console.log(this.jobName)
      const data = {
        jobName: this.jobName,
      }
      if (this.jobName === '') {
        this.isSearchList = false
      } else {
        this.isSearchList = true
        this.$request.post('/api/api/JobInfo/SelectMore', data).then((res) => {
          // console.log(res)
          this.searchData = res.data
        })
      }
    },
    getSearch() {
      sessionStorage.setItem('jobSearch', this.jobName)
      if (this.jobName !== '') { 
        this.$router.push({
          name: 'jobList',
          params: {
            jobName: this.jobName
          }
        })
      }
    }
  },
}
</script>
<style scoped>
.Search{
  width: 100%;
  height: 130px;
  margin-top: 20px;
}
.search-wrap {
  width: 800px;
  height: 50px;
  margin: auto;
}
.search-ipt {
  width: 640px;
  height: 50px;
  border: none;
  padding-left: 10px;
  font-size: 16px;
  color: #414a60;
  outline: none;
  box-shadow: 0 0 6px 0 rgb(0 0 0 / 13%);
}
.search-btn {
  width: 140px;
  height: 54px;
  padding-bottom: 4px;
  background-color: #55cbc4;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.search-btn:hover {
  background-color: #5dd5cb;
}
.search-hidden {
  width: 640px;
  height: 200px;
  background-color: #fff;
  position: relative;
  top: 4px;
  left: 366px;
  overflow: scroll;
}
.search-hidden-list {
  /* width: 652px; */
  height: 30px;
  line-height: 30px;
  padding-left: 10px;
  margin: 10px 0 ;
  cursor: pointer;
}
.search-hidden-list:hover{
  background-color: #f0f9eb;
}
</style>